﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;

namespace AssetManager
{
    public partial class frmLogin : Form
    {
        private AssetServiceRef.User user;
        
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            AssetServiceRef.AssetServiceClient sr = new AssetServiceRef.AssetServiceClient();
            try
            {

                string un = txtUsername.Text.ToString();
                string pw = txtPassword.Text.ToString();
                user = sr.Login(un, pw);
                if (user != null)
                {
                    frmMain frmMain = new frmMain(this, user);
                    this.Hide();
                    frmMain.Show();
                }
                else
                {
                    lblError.Hide();
                    UsernameValue = "";
                    PasswordValue = "";
                    txtUsername.Focus();
                    lblError.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public string UsernameValue
        {
            get { return txtUsername.Text; }
            set { txtUsername.Text = value; }
        }

        public string PasswordValue
        {
            get { return txtPassword.Text; }
            set { txtPassword.Text = value; }
        }

        private void frmLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        //private void lblRegister_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        //{
        //    frmRegister frmRegister = new frmRegister();
        //    frmRegister.Show();
        //    this.Hide();
        //}
    }
}
